package com.hzgj.bcl.soa.cicada.lb;

import com.hzgj.bcl.soa.cicada.sender.Sender;

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

/**
 * Interface that defines a "Rule" for a LoadBalancer. A Rule can be thought of
 * as a Strategy for loadbalacing. Well known loadbalancing strategies include
 * Round Robin, Response Time based etc.
 */
public interface Rule {
    /*
     * choose one alive server from lb.allServers or
     * lb.upServers according to key
     * 
     * @return choosen Server object. NULL is returned if none
     *  server is available 
     */

    Sender choose(Object key);

    String getName();

    LoadBalancer getLoadBalancer();

    void setLoadBalancer(LoadBalancer lb);

    @Builder
    @Getter
    @ToString
    class RuleObject {
        String service;
        String method;
        String rule;
    }
}
